﻿using System.Threading.Tasks;

using Hang.Blog.Application.Contracts.Dtos.Users;
using Hang.Blog.Helper;
using Hang.Blog.Inter;
using Hang.Blog.RepositoryInter;
using Hang.Blog.Users;

using Microsoft.AspNetCore.Mvc;

using Volo.Abp;
using Volo.Abp.Domain.Repositories;

namespace Hang.Blog.Imp {
    [Route(StringConsts.Api + "user")]
    public class UserAppService : BlogAppService, IUserAppService
    {

        private readonly IBlogRepository<AppUser> _identityUserRepository;
        public UserAppService(IBlogRepository<AppUser> identityUserRepository)
        {
            _identityUserRepository = identityUserRepository;
        }



        [HttpGet]
        [Route("info")]
        public async Task<CurrentUserDto> Info()
        {
            var user = await _identityUserRepository.FirstOrDefaultAsync(x => x.Id == CurrentUser.Id);
            if (user == null)
            {
                throw new BusinessException("用户没有登录");
            }
            var _currentUser = new CurrentUserDto()
            {
                Id = user.Id,
                UserName = user.UserName,
                Name=user.Name
            };
            return _currentUser;
        }
    }
}
